package com.lineage.server.clientpackets;

import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.Instance.L1SkinInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.serverpackets.S_ChangeHeading;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Iterator;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_ChangeHeading extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_ChangeHeading.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      Map<Integer, L1SkinInstance> skinList;
      read(decrypt);
      L1PcInstance pc = client.getActiveChar();
      pc.isGhost();
      if (pc.isDead() || pc.isTeleport())
        return; 
      int heading = readC();
      switch (heading) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
          pc.setHeading(heading);
          if (!pc.isGmInvis() && !pc.isGhost() && !pc.isInvisble())
            pc.broadcastPacketAll((ServerBasePacket)new S_ChangeHeading((L1Character)pc)); 
          skinList = pc.getSkins();
          if (skinList.size() > 0) {
            Iterator<Integer> iterator = skinList.keySet().iterator();
            while (iterator.hasNext()) {
              Integer gfxid = iterator.next();
              L1SkinInstance skin = skinList.get(gfxid);
              skin.setHeading(heading);
              skin.broadcastPacketAll((ServerBasePacket)new S_ChangeHeading((L1Character)skin));
            } 
          } 
          break;
      } 
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
